package com.heima.wemedia.config;

import com.heima.common.constants.rabbit.RabbitArticleDownOrUpConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DeclareRabbitArticleDownOrUpConfig {
    @Bean
    public TopicExchange articleDownOrUpExchange(){
        return new TopicExchange(RabbitArticleDownOrUpConstants.ARTICLE_DOWN_OR_UP_EXCHANGE, true, false);
    }

    @Bean
    public Queue articleDownForConfigQueue(){
        return QueueBuilder.durable(RabbitArticleDownOrUpConstants.ARTICLE_DOWN_FOR_CONFIG_QUEUE)
                .build();
    }

    @Bean
    public Queue articleUpForConfigQueue(){
        return QueueBuilder.durable(RabbitArticleDownOrUpConstants.ARTICLE_UP_FOR_CONFIG_QUEUE)
                .build();
    }

    @Bean
    public Queue articleDownForEsQueue(){
        return QueueBuilder.durable(RabbitArticleDownOrUpConstants.ARTICLE_DOWN_FOR_ES_QUEUE)
                .build();
    }

    @Bean
    public Queue articleUpForEsQueue(){
        return QueueBuilder.durable(RabbitArticleDownOrUpConstants.ARTICLE_UP_FOR_ES_QUEUE)
                .build();
    }

    @Bean
    public Binding bindingArticleDownForConfigQueue(){
        return BindingBuilder.bind(articleDownForConfigQueue())
                .to(articleDownOrUpExchange())
                .with(RabbitArticleDownOrUpConstants.CONFIG_DOWN_BINDING_KEY);
    }

    @Bean
    public Binding bindingArticleUpForConfigQueue(){
        return BindingBuilder.bind(articleUpForConfigQueue())
                .to(articleDownOrUpExchange())
                .with(RabbitArticleDownOrUpConstants.CONFIG_UP_BINDING_KEY);
    }

    @Bean
    public Binding bindingArticleDownForEsQueue(){
        return BindingBuilder.bind(articleDownForEsQueue())
                .to(articleDownOrUpExchange())
                .with(RabbitArticleDownOrUpConstants.ES_DOWN_BINDING_KEY);
    }

    @Bean
    public Binding bindingArticleUpForEsQueue(){
        return BindingBuilder.bind(articleUpForEsQueue())
                .to(articleDownOrUpExchange())
                .with(RabbitArticleDownOrUpConstants.ES_UP_BINDING_KEY);
    }
}
